package com.zywl.service.impl;

import com.zywl.core.beans.User;
import com.zywl.core.dao.mapper.sys.UserMapper;
import com.zywl.service.UserService;
import com.zywl.service.impl.base.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> getUsersByRoleId(String roleId) throws Exception {
        Map<String, Object> condition = new HashMap<String, Object>();
//        condition.put("order", "ROLE_LEVEL");
        condition.put("usr_role_id", roleId);
        condition.put("usr_stt", "0");
        return mapper.getListByParams(condition);
    }

    @Override
    public User getUsersByUsername(String usrUsername) throws Exception {
        Map<String, Object> condition = new HashMap<String, Object>();
        condition.put("usr_username", usrUsername);
        List<User> users = mapper.getListByParams(condition);
        if (users != null && !users.isEmpty()) {
            return users.get(0);
        }
        return null;
    }

    @Override
    public User getUsersByIdCard(String idCard) throws Exception {
        Map<String, Object> condition = new HashMap<String, Object>();
        condition.put("ID_CARD", idCard);
        List<User> users = mapper.getListByParams(condition);
        if (users != null && !users.isEmpty()) {
            return users.get(0);
        }
        return null;
    }

    @Override
    public List<User> getByLikeRoleName(Map<String,Object> map)throws Exception{
//        return userMapper.selectByLikeRoleName(map);
        return null;
    }

    @Override
    public User getUsersByUserName(String userName)throws Exception{
        Map<String, Object> condition = new HashMap<String, Object>();
        condition.put("usr_username", userName);
        List<User> users = mapper.getListByParams(condition);
        if (users != null && !users.isEmpty()) {
            return users.get(0);
        }
        return null;
    }
}
